from typing import List

from langchain.embeddings.base import Embeddings
import numpy as np

class CustomEmbeddings(Embeddings):
    def embed_query(self, text: str) -> List[float]:
        # 这里可以替换为你的自定义嵌入逻辑
        return np.random.rand(128).tolist()

    def embed_documents(self, texts: List[str]) -> List[List[float]]:
        return [self.embed_query(text) for text in texts]

# 初始化自定义嵌入对象
embeddings = CustomEmbeddings()

# 示例文本
texts = ["今天天气怎么样？", "把下面的语句翻译为英文。"]

# 生成嵌入向量
embeddings_vectors = embeddings.embed_documents(texts)

# 输出嵌入向量
for vector in embeddings_vectors:
    print(vector)